package onki.tests;
import onki.tests.pageObjects.OnkiConceptPageObject;
import java.util.ArrayList;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.testng.annotations.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.PageFactory;

/**
 *
 * @author henriyli
 */
@Test(groups = {"english"})
public class CatCompletenessEN extends OnkiTestBase {

  private WebDriver driver;
  private OnkiConceptPageObject catConceptPage;

  public CatCompletenessEN() {
    conceptUri = "http://www.yso.fi/onto/yso/p19378";
  }

  @BeforeClass
  public void setUp() {
    driver = new FirefoxDriver();
    this.catConceptPage = loadConcept(conceptUri, "en");
  }
  
  public void hasProperTitle() {
    assertTrue(this.driver.getTitle().contentEquals("ONKI: YSO: cat"));
  }

  public void catPageHasCorrectPreflabel() {
    assertTrue(this.catConceptPage.getLabel().contains("cat"));
  }

  public void catPageHasCorrectType() {
    assertTrue(this.catConceptPage.getType().contains("Concept"));
  }

  public void catPageHasCorrectBroaderRelations() {
    ArrayList<String> broaders = this.catConceptPage.getBroaderRelations();
    assertTrue(broaders.contains("felines"));
  }

  public void catPageHasCorrectNarrowerRelations() {
    ArrayList<String> narrowers = this.catConceptPage.getNarrowerRelations();
    assertTrue(narrowers.contains("Burmese (cat)"));
    assertTrue(narrowers.contains("European shorthair"));
    assertTrue(narrowers.contains("Norwegian forest cat"));
    assertTrue(narrowers.contains("Persian"));
    assertTrue(narrowers.contains("Siamese"));
    assertTrue(narrowers.contains("Siberian"));
    assertTrue(narrowers.contains("birman"));
    assertTrue(narrowers.contains("devon rex"));
    assertTrue(narrowers.contains("exotic (breed of cat)"));
    assertTrue(narrowers.contains("korat"));
  }

  public void catPageHasCorrectRelatedConcepts() {
    ArrayList<String> related = this.catConceptPage.getRelatedConcepts();
    assertTrue(related.contains("pets"));
  }

  public void catPageHasCorrectUri() {
    assertEquals(this.catConceptPage.getUri(), conceptUri);
  }

  @AfterClass
  public void tearDown() {
    driver.quit();
  }
  
  public OnkiConceptPageObject loadConcept(String uri, String lang) {
    this.driver.get(lightenUrl(uri, lang));
    OnkiConceptPageObject cat = PageFactory.initElements(this.driver, OnkiConceptPageObject.class);
    return cat;
  }

}
